<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <link th:href="@{https://cdn.bootcss.com/twitter-bootstrap/3.0.1/css/bootstrap.min.css}" rel="stylesheet">
    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
</head>
<body>
<!--<span th:text="${pageInfo.list}"></span>-->
<div class="container">
    <div class="row clearfix">
        <div class="col-md-12 column">
            <!--<button type="button" class="btn btn-default">按钮</button>-->
            <h1 class="text-center">
                新闻列表
            </h1>

            <div>
                新闻标题<input type="text" name="selectName" id="selectTitle" th:value="${title}">
                <span></span>
                <input type="button" value="查询" onclick="sendTitle()">
            </div>

            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>新闻编号</th>
                    <th>新闻标题</th>
                    <th>新闻摘要</th>
                    <th>作者</th>
                    <th>创建时间</th>
                    <th>操作</th>

                </thead>
                <tbody>
                <tr th:each="detail:${pageInfo.list}">
                    <td th:text="${detail.id}" id="needId" ></td>
                    <td th:text="${detail.title}"></td>
                    <td th:text="${detail.summary}"></td>
                    <td th:text="${detail.author}"></td>
                    <td th:text="${#dates.format(detail.createdate,'yyyy-MM-dd')}"></td>
                    <td ><a href="javascript:;" onclick="viewCommons()" >查看评论</a>
                         <a th:href="@{/news/addcomment-ui(id=${detail.id})}" >评论</a>
                         <a th:href="@{/news/delete(id=${detail.id})}" >删除</a>
                    </td>

                </tr>

            </table>
            <span>第<i th:text="${pageInfo.getPageNum()}"></i> 页 共<i th:text="${pageInfo.getPages()}"></i> 页</span>
            <ul class="pagination" style="float: right">
                <li>
                    <a href="javascript:;" onclick="page(1)">首页</a>
                </li>
                <li>
                    <a href="javascript:;" th:onclick="page([[${pageInfo.pageNum-1}]])">上一页</a>
                </li>
                <li>
                    <a href="javascript:;"  th:onclick="page([[${pageInfo.pageNum+1}]])">下一页</a>
                </li>
                <li>
                    <a href="javascript:;"  th:onclick="page([[${pageInfo.pages}]])">尾页</a>
                </li>

            </ul>
        </div>
    </div>
</div>

<script>
    function sendTitle() {
       var title= $("#selectTitle").val();
       // console.log(title)
       //  alert(title)
       location.href="/news/index?title="+title;

    }

    function page(page) {
        location.href="/news/index?page="+page;
    }

    function viewCommons() {
        location.href="/news/viewCommons"

    }

    //这个为啥不行
    function addcomment() {
        var needId =$("#needId").val();

        console.log(needId);
        alert(needId)
        location.href="/news/addcomment-ui?needId="+needId;
    }
</script>

</body>
</html>